/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cs.princeton.edu;




/**
 *
 * @author manuel
 */
public class DCClient {

    public static void main(String[] args){
        quickFind();
        System.out.println("\n-----------------------\n");
        weightedQuickFind();
        /*
        int N = StdIn.readInt();
        //QuickFindUF uf = new QuickFindUF(N);
        WeightedQuickUnionUF uf = new WeightedQuickUnionUF(N);
        while(!StdIn.isEmpty()){
            int p = StdIn.readInt();
            int q = StdIn.readInt();
            if(!uf.connected(p, q)){
                uf.union(p, q);
                StdOut.println(p + " " + q);
            }
            
        }
        */
        //testWeightQuickUnionUF();
    }
    private static void quickFind(){
        int N = 10;
        QuickFindUF uf = new QuickFindUF(N);
        //seed(93740)
        if(!uf.connected(6, 2)) uf.union(6, 2);
        if(!uf.connected(0, 9)) uf.union(0, 9);
        if(!uf.connected(3, 9)) uf.union(3, 9);
        if(!uf.connected(8, 9)) uf.union(8, 9);
        if(!uf.connected(5, 8)) uf.union(5, 8);
        if(!uf.connected(4, 6)) uf.union(4, 6);
        
    }
    private static void weightedQuickFind(){
        int N = 10;
        WeightedQuickUnionUF uf = new WeightedQuickUnionUF(N);
        //seed(398743)
        if(!uf.connected(4, 8)) uf.union(4, 8);
        if(!uf.connected(1, 9)) uf.union(1, 9);
        if(!uf.connected(3, 5)) uf.union(3, 5);
        if(!uf.connected(2, 7)) uf.union(2, 7);
        if(!uf.connected(6, 4)) uf.union(6, 4);
        if(!uf.connected(7, 9)) uf.union(7, 9);
        if(!uf.connected(5, 4)) uf.union(5, 4);
        if(!uf.connected(3, 9)) uf.union(3, 9);
        if(!uf.connected(4, 0)) uf.union(4, 0);
        
    }
    /**
     * Union operations
     *  4-6 4-7 6-1 6-3 9-2 8-4 0-5 9-0 1-9
     */
    private static void testWeightQuickUnionUF(){
        int N = 10;
        WeightedQuickUnionUF uf = new WeightedQuickUnionUF(N);
        if(!uf.connected(4, 6)) uf.union(4, 6);
        System.out.println("e:[0;1;2;3;4;5;4;7;8;9]\n");
        if(!uf.connected(4, 7)) uf.union(4, 7);
        System.out.println("e:[0;1;2;3;4;5;4;4;8;9]\n");
        if(!uf.connected(6, 1)) uf.union(6, 1);
        System.out.println("e:[0;4;2;3;4;5;4;4;8;9]\n");
        if(!uf.connected(6, 3)) uf.union(6, 3);
        System.out.println("e:[0;4;2;4;4;5;4;4;8;9]\n");
        if(!uf.connected(9, 2)) uf.union(9, 2);
        System.out.println("e:[0;4;9;4;4;5;4;4;8;9]\n");
        if(!uf.connected(8, 4)) uf.union(8, 4);
        System.out.println("e:[0;4;9;4;4;5;4;4;4;9]\n");
        if(!uf.connected(0, 5)) uf.union(0, 5);
        System.out.println("e:[0;4;9;4;4;0;4;4;4;9]\n");
        if(!uf.connected(9, 0)) uf.union(9, 0);
        System.out.println("e:[9;4;9;4;4;0;4;4;4;9]\n");
        if(!uf.connected(1, 9)) uf.union(1, 9);
        System.out.println("e:[9;4;9;4;4;0;4;4;4;4]\n");
       
        
        //9 4 9 4 4 0 4 4 4 4
    }
}
